package chu.dejian.ui.fragmet;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import com.sam.blemodule.R;

import com.sam.ui.base.fragment.BaseParentFragment;
import com.sam.ui.base.fragment.InteractionFragment;
import com.sam.widget.headerBar.BaseHeaderView;
import com.sam.widget.headerBar.LeftImgSegmentedRightImgBar;
import com.sam.widget.segmented.OnSegmentCheckedChangeListener;
import com.sam.widget.segmented.SegmentedBar;

import chu.dejian.ui.activity.AttentionApplyActivity;

public class AttentionFragment extends BaseParentFragment implements InteractionFragment.OnFragmentInteractionListener {
	private static AttentionFragment instance;
	public synchronized static AttentionFragment getInstance(){
		if(instance == null){
			instance = new AttentionFragment();
		}
		return instance;
	}
	private LeftImgSegmentedRightImgBar header;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_attention);
//		showFragment(R.id.sub_fragment_content, AttentionSendedRequestFragment.getInstance());
	}

	@Override
	protected void findView() {
		header = (LeftImgSegmentedRightImgBar) findViewById(R.id.header);
	}

	@Override
	protected void initView() {
		header.setSegmentInfo(new String[]{getResources().getString(R.string.my_attention),
				getResources().getString(R.string.sended_attention_request)},0,onSegmentCheckedChangeListener);
		header.setOnHeaderClickListener(onHeaderClickListener);
	}

	private OnSegmentCheckedChangeListener onSegmentCheckedChangeListener = new OnSegmentCheckedChangeListener() {
		@Override
		public void onSegmentCheckedChanged(ViewGroup segmentedBar, int position, TextView segmentButton) {
			switch (position){
				case 0: // 我关注的
					onReplaceSelfWithFragment(MyAttentionFragment.getInstance());
					break;
				case 1: // 发送的请求
					onReplaceSelfWithFragment(AttentionSendedRequestFragment.getInstance());
					break;
			}
		}
	};
	private BaseHeaderView.OnHeaderClickListener onHeaderClickListener = new BaseHeaderView.OnHeaderClickListener() {
		@Override
		public void onHeaderLeftClicked() {

		}

		@Override
		public void onHeaderRightClicked() {
			startActivity(new Intent(getActivity(),AttentionApplyActivity.class));
		}
	};

	@Override
	public void onReplaceSelfWithFragment(Fragment fragment) {
//		showFragment(R.id.sub_fragment_content,fragment);
		replaceFragment(R.id.sub_fragment_content,fragment);
	}

	@Override
	public void onBackToPreviewFragment() {
		getChildFragmentManager().popBackStack();
	}
}
